package org.streets.database.datadict.impl;

import org.streets.commons.util.StringUtils;
import org.streets.database.datadict.Relation;

public class RelationImpl implements Relation {
	
	private String hostTable;
	private String targetTable;

	private String hostColumn;
	private String targetColumn;
	
	RelationImpl(String express) {
		String host_str = StringUtils.left(express, express.indexOf("->"));
		String target_str = StringUtils.substringAfter(express, ">");
		String[] hosts = host_str.split("\\.");
		hostTable = hosts[0].trim();
		hostColumn = hosts[1].trim();
		String[] targets = target_str.split("\\.");
		targetTable = targets[0].trim();
		targetColumn = targets[1].trim();
	}
	
	/* (non-Javadoc)
	 * @see org.streets.database.datadict.impl.Relation#getHostTable()
	 */
	public String getHostTable() {
		return hostTable;
	}
	
	public void setHostTable(String hostTable) {
		this.hostTable = hostTable;
	}
	
	/* (non-Javadoc)
	 * @see org.streets.database.datadict.impl.Relation#getTargetTable()
	 */
	public String getTargetTable() {
		return targetTable;
	}
	
	public void setTargetTable(String targetTable) {
		this.targetTable = targetTable;
	}
	
	/* (non-Javadoc)
	 * @see org.streets.database.datadict.impl.Relation#getHostColumn()
	 */
	public String getHostColumn() {
		return hostColumn;
	}
	
	public void setHostColumn(String hostColumn) {
		this.hostColumn = hostColumn;
	}
	
	/* (non-Javadoc)
	 * @see org.streets.database.datadict.impl.Relation#getTargetColumn()
	 */
	public String getTargetColumn() {
		return targetColumn;
	}
	
	public void setTargetColumn(String targetColumn) {
		this.targetColumn = targetColumn;
	}
	
	@Override
	public String toString() {
		return hostTable+"."+hostColumn+" -> "+targetTable+"."+targetColumn;
	}
}
